var panel = null;

function initConsolePanel(){
	Ext.QuickTips.init();
	
	var root = new Ext.tree.TreeNode({
		expandable : true,
		expanded : true
	});
	
	var affair = new Ext.tree.TreeNode({
		text : '新闻动态',
		icon : '../images/admin/icon_affair.png',
		leaf : true,
		qtip : '管理胡萝卜的最近动态',
		listeners : {
			'click' : function(){
				panel = Ext.getCmp('mainPanel');
				if(panel == null){
					panel = new Ext.Panel({width : 1315, height : 588});
				}
				panel.load({
				        url : 'affairAction_forward.action',
				        method : 'POST',
				        nocache : false,
				        scripts : true
			    });
				
			}
		}
	});
	
	var product = new Ext.tree.TreeNode({
		text : '产品管理',
		icon : '../images/admin/icon_product.png',
		leaf : true,
		qtip : '管理胡萝卜制作的APK',
		listeners : {
			'click' : function(){
				panel = Ext.getCmp('mainPanel');
				if(panel == null){
					panel = new Ext.Panel({width : 1315, height : 588});
				}
				panel.load({
				        url : 'productAction_forward.action',
				        nocache : false,
				        scripts : true
			    });
			}
		}
	});
	
	var user = new Ext.tree.TreeNode({
		text : '用户管理',
		icon : '../images/admin/icon_user.png',
		leaf : true,
		qtip : '管理注册胡萝卜网站的用户',
		listeners : {
			'click' : function(){
				panel = Ext.getCmp('mainPanel');
				if(panel == null){
					panel = new Ext.Panel({width : 1315, height : 588});
				}
				panel.load({
				        url : 'userAction_forward.action',
				        nocache : false,
				        scripts : true
			    });
			}
		}
	});
	
	var message = new Ext.tree.TreeNode({
		text : '留言管理',
		icon : '../images/admin/icon_message.png',
		leaf : true,
		qtip : '与关心胡萝卜的用户进行交流',
		listeners : {
			'click' : function(){
				if(panel == null){
					panel = Ext.getCmp('mainPanel');
				}
				panel.load({
				        url : 'messageAction_forward.action',
				        nocache : false,
				        scripts : true
			    });
			}
		}
	});
	
	var link = new Ext.tree.TreeNode({
		text : '友情链接',
		icon : '../images/admin/icon_link.png',
		leaf : true,
		qtip : '一个好汉三个帮，一个萝卜三个桩~',
		listeners : {
			'click' : function(){
				panel = Ext.getCmp('mainPanel');
				if(panel == null){
					panel = new Ext.Panel({width : 1315, height : 588});
				}
				panel.load({
				        url : 'linkAction_forward.action',
				        nocache : false,
				        scripts : true
			    });
			}
		}
	});
	
	var img = new Ext.tree.TreeNode({
		text : '图片管理',
		icon : '../images/common/icon_picture.png',
		leaf : true,
		qtip : '管理图片素材',
		listeners : {
			'click' : function(){
				panel = Ext.getCmp('mainPanel');
				if(panel == null){
					panel = new Ext.Panel({width : 1315, height : 588});
				}
				panel.load({
				        url : 'imageAction_forward.action',
				        nocache : false,
				        scripts : true
			    });
			}
		}
	});
	
	root.appendChild(affair);
	root.appendChild(product);
	root.appendChild(user);
	root.appendChild(message);
	root.appendChild(link);
	root.appendChild(img);
	
	new Ext.Viewport({
		layout : 'border',
		items : [
		         	{
		         		region : 'north',
		         		xtype : 'panel',
		         		height : 88,
		         		border : false,
		         		margins : {top:0, right:0, bottom:0, left:18},
		         		bodyStyle : 'background:url(../images/admin/console_header.png) no-repeat left top;'
		         	},
		         	{
		         		region : 'west',
		         		xtype : 'treepanel',
		         		frame : true,
		         		padding : 6,
		         		collapsible : true,
		         		border : true,
		         		autoScroll: true,
	         			title : '胡萝卜控制台',
	         			lines : false,
	         			rootVisible : false,
	         			root : root
		         	},
		         	{
		         		region : 'center',
		         		xtype : 'panel',
		         		id : 'mainPanel',
		         		border : true,
		         		title : '操作台',
		         		bodyStyle : 'background:url(../images/admin/console_header.png) no-repeat center;'
		         	}
		         ]
	});
};

Ext.onReady(function(){
	initConsolePanel();
});
	